package com.njh.charges.controller.apis;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hos.entity.his.OrderCharge;
import com.hos.entity.his.OrderChargeItem;
import com.hos.vo.Result;
import com.njh.charges.service.ChargeService;
import com.njh.charges.service.HandleMedicineService;
import com.njh.charges.vo.AllOrderChargeVo;
import com.njh.charges.vo.OrderChargeDtoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author ：njh
 * @date ：Created in 2023/12/14 11:21
 * @description：收费列表
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/charges/api/charge")
@Api(tags = "收费列表相关接口")
public class ApiChargeController {

    @Resource
    private ChargeService chargeService;
    @Resource
    private HandleMedicineService handleMedicineService;


    @GetMapping("getNoChargeCareHistoryByRegId/{regId}")
    @ApiOperation("根据挂号ID查询未支付的处方信息及详情")
    public Result getNoChargeCareHistoryByRegId(@PathVariable String regId) {

        Map noChargeCareHistoryByRegId = handleMedicineService.getNoChargeCareHistoryByRegId(regId);
        Result<Map> result = new Result<>(200, "查询成功", noChargeCareHistoryByRegId);

        return result;
    }

    @PostMapping("createOrderChargeWithCash")
    @ApiOperation("处方收费里面的现金支付")
    public Result createOrderChargeWithCash(@RequestBody OrderChargeDtoVo orderChargeDtoVo) {

        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
        System.out.println(orderChargeDtoVo);
        System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");

        Boolean orderChargeWithCash = chargeService.createOrderChargeWithCash(orderChargeDtoVo);
        Result<Boolean> result = new Result<>(200, "支付成功", orderChargeWithCash);

        return result;
    }



    @PostMapping("queryAllOrderChargeForPage")
    @ApiOperation("分页查询收费列表")
    public Result queryAllOrderChargeForPage(@RequestBody AllOrderChargeVo allOrderChargeVo) {

        Page<OrderCharge> orderChargePage = chargeService.queryAllOrderChargeForPage(allOrderChargeVo);
        Result<Page<OrderCharge>> result = new Result<Page<OrderCharge>>(200, "查询成功", orderChargePage);

        return result;
    }

    @GetMapping("queryOrderChargeItemByOrderId/{orderId}")
    @ApiOperation("根据订单号查询收费详情列表")
    public Result queryOrderChargeItemByOrderId(@PathVariable String orderId) {

        List<OrderChargeItem> orderChargeItems = chargeService.queryOrderChargeItemByOrderId(orderId);
        Result<List<OrderChargeItem>> result = new Result<List<OrderChargeItem>>(200, "查询成功", orderChargeItems);

        return result;
    }

    @GetMapping("payWithCash/{orderId}")
    @ApiOperation("根据订单号进行现金支付")
    public Result payWithCash(@PathVariable String orderId) {

        int i = chargeService.payWithCash(orderId);
        if(i>0){
            Result<Integer> result = new Result<>(200, "支付成功", i);
            return result;
        }else{
            Result<Integer> result = new Result<>(200, "支付失败", i);
            return result;
        }


    }
}